#include "Game.h"

Game::Game(int windowX, int windowY, String winTitle)
{
	m_isRunning = false;
	m_rezX = windowX;
	m_rezY = windowY;
	m_title = winTitle;
	m_BackBufferColour = Color(0,148,255);
	m_FPS = 0;
	return; //
}
Game::~Game() 
{
	if(m_Window != NULL)
	{
		delete m_Window;
		m_Window = NULL;
	}
}


void Game::Exit() {
	m_isRunning = false;
}
void Game::Run() {
	//Init of things
	m_Window = new RenderWindow(sf::VideoMode(m_rezX, m_rezY), m_title);
	Content = new ContentPipeline();
	m_InputControl = new InputController();
	
	if(!Init())
		return;
	if(!Content->Load())
		return;

	//The Game Loop
	int frames = 0;
	Clock clock;
	Time elapsedTime; 

	m_isRunning = true;
	while (m_Window->isOpen() && m_isRunning)
    {		
		//Closes event Stuff
        sf::Event event;
        while (m_Window->pollEvent(event))
        {
            switch(event.type)			
			{
				case Event::Closed:				
					m_Window->close();
					break;

				case Event::KeyPressed:
				case Event::KeyReleased:
					break;

			}
			
        }

		//Update FPS
		clock.restart();
		elapsedTime += clock.getElapsedTime();
		if(elapsedTime > sf::seconds(1))
		{
			m_FPS = frames;
			frames = 0;
			elapsedTime = sf::seconds(0);
		}
		
		
		//Updates
		m_InputControl->Update(clock.getElapsedTime());
		Update(clock.getElapsedTime());

		//Start Rendering
        m_Window->clear(m_BackBufferColour);	       
		Render(*m_Window, *Content, clock.getElapsedTime());
		
		//Draw FPS Font
		Text fpsTxt = Text();
		fpsTxt.setFont(*(Content->Default));
		fpsTxt.setString("FPS");
		fpsTxt.setPosition(0,0);
		fpsTxt.setCharacterSize(14U);

		m_Window->draw(fpsTxt);
		m_Window->display();

		frames++;
    }
}

bool Game::Init()
{//TODO: LOADING LOGIC


	return true;
}
bool Game::Render(RenderWindow &window, ContentPipeline &content, Time &gameTime)
{//TODO: RENDER LOGIC

	
	return true;
}
bool Game::Update(Time &gameTime)
{//TODO: UPDATE LOGIC

	return true;
}
